﻿//<TunynetCopyright>
//--------------------------------------------------------------
//<copyright>青岛拓宇网络科技有限公司 2005-2008</copyright>
//<version>V0.5</verion>
//<createdate>2008-2-22</createdate>
//<author>zhengw</author>
//<email>zhengw@tunynet.com</email>
//<log date="2008-2-22">创建</log>
//--------------------------------------------------------------
//</TunynetCopyright>

using System;
using System.Collections.Generic;
using System.Text;
using Tunynet.QingdaoCustoms.Serialization;
using ChinaCustoms.Qingdao.Workflow.Permissions;

namespace ChinaCustoms.Qingdao.Workflow.Supports
{
    /// <summary>
    /// 工作项实体类
    /// </summary>
    [Serializable]
    public class WorkItemInfo : ExtendedAttributes
    {
        private Guid workItemGuid;
        /// <summary>
        /// 工作项ID
        /// </summary>
        public Guid WorkItemGuid
        {
            get { return this.workItemGuid; }
            set { this.workItemGuid = value; }
        }

        private Guid activityGuid = Guid.Empty;
        /// <summary>
        /// 活动GUID
        /// </summary>
        public Guid ActivityGuid
        {
            get { return this.activityGuid; }
            set { this.activityGuid = value; }
        }

        private string activityName = string.Empty;
        /// <summary>
        /// 活动名称
        /// </summary>
        public string ActivityName
        {
            get { return activityName; }
            set { activityName = value; }
        }


        private Guid taskGuid;
        /// <summary>
        /// 任务ID
        /// </summary>
        public Guid TaskGuid
        {
            get { return this.taskGuid; }
            set { this.taskGuid = value; }
        }

        private Guid subTaskGuid = Guid.Empty;
        /// <summary>
        /// 所在子流程GUID
        /// </summary>
        public Guid SubTaskGuid
        {
            get { return this.subTaskGuid; }
            set { this.subTaskGuid = value; }
        }

        private string workItemName = string.Empty;
        /// <summary>
        /// 工作项名称
        /// </summary>
        public string WorkItemName
        {
            get { return this.workItemName; }
            set { this.workItemName = value; }
        }

        private Guid previousWorkItemGuid = Guid.Empty;
        /// <summary>
        /// 前WorkItemID
        /// </summary>
        public Guid PreviousWorkItemGuid
        {
            get { return this.previousWorkItemGuid; }
            set { this.previousWorkItemGuid = value; }
        }

        private string creatorUserName = string.Empty;
        /// <summary>
        /// 创建者用户名
        /// </summary>
        public string CreatorUserName
        {
            get { return creatorUserName; }
            set { creatorUserName = value; }
        }

        private string creatorDisplayName = string.Empty;
        /// <summary>
        /// 创建者姓名
        /// </summary>
        public string CreatorDisplayName
        {
            get { return creatorDisplayName; }
            set { creatorDisplayName = value; }
        }

        private string creatorFullPath = string.Empty;
        /// <summary>
        /// 创建者全路径名
        /// </summary>
        public string CreatorFullPath
        {
            get { return creatorFullPath; }
            set { creatorFullPath = PermissionUtils.FormatUserFullPath(value); }
        }

        private string executorUserName = string.Empty;
        /// <summary>
        /// 工作项执行人
        /// </summary>
        public string ExecutorUserName
        {
            get { return this.executorUserName; }
            set { this.executorUserName = value; }
        }

        private string executorDisplayName = string.Empty;
        /// <summary>
        /// 任务执行人姓名
        /// </summary>
        public string ExecutorDisplayName
        {
            get { return executorDisplayName; }
            set { executorDisplayName = value; }
        }

        private string executorFullPath = string.Empty;
        /// <summary>
        /// 任务执行人全路径名
        /// </summary>
        public string ExecutorFullPath
        {
            get { return executorFullPath; }
            set { executorFullPath = PermissionUtils.FormatUserFullPath(value); }
        }

        private WorkItemStatus status = WorkItemStatus.Queuing;
        /// <summary>
        /// 状态
        /// </summary>
        public WorkItemStatus Status
        {
            get { return this.status; }
            set { this.status = value; }
        }

        private WorkItemExecutionResult executionResult = WorkItemExecutionResult.NotSet;
        /// <summary>
        /// 执行结果
        /// </summary>
        /// <remarks>
        /// 当工作项状态是Completed时，有可能是批准后完成，也有可能是拒绝后完成
        /// </remarks>
        public WorkItemExecutionResult ExecutionResult
        {
            get { return executionResult; }
            set { executionResult = value; }
        }

        private WorkItemType workItemType = WorkItemType.StartTask;
        /// <summary>
        /// 工作项类型
        /// </summary>
        public WorkItemType WorkItemType
        {
            get { return this.workItemType; }
            set { this.workItemType = value; }
        }

        private string postil = string.Empty;
        /// <summary>
        /// 审批意见
        /// </summary>
        public string Postil
        {
            get { return this.postil; }
            set { this.postil = value; }
        }

        private DateTime createDate;
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateDate
        {
            get { return this.createDate; }
            set { this.createDate = value; }
        }

        private DateTime lastUpdateDate;
        /// <summary>
        /// 上次更新日期
        /// </summary>
        public DateTime LastUpdateDate
        {
            get { return this.lastUpdateDate; }
            set { this.lastUpdateDate = value; }
        }

        #region 序列化属性

        /// <summary>
        /// 拒绝执行的SubTaskGuid
        /// </summary>
        public Guid SubTaskGuidOfReject
        {
            get { return GetGuid("SubTaskGuidOfReject", Guid.Empty); }
            set { SetExtendedAttribute("SubTaskGuidOfReject", value.ToString()); }
        }

        #endregion


        #region 扩展属性

        private ActivityInstanceInfo activity = null;
        /// <summary>
        /// 所属ActivityInstance
        /// </summary>
        public ActivityInstanceInfo Activity
        {
            get
            {
                if (activity == null)
                    activity = ActivityInstances.GetActivity(this.ActivityGuid);

                return activity;
            }
        }

        private TaskInfo task = null;
        /// <summary>
        /// 所属Task
        /// </summary>
        public TaskInfo Task
        {
            get
            {
                if (task == null)
                    task = Tasks.GetTask(this.TaskGuid);

                return task;
            }
        }

        #endregion

    }
}
